package org.elanfox.intellicommunity.msg.server.service;

import org.apache.http.MethodNotSupportedException;
import org.elanfox.intellicommunity.msg.ienum.CmdEnums;
import org.elanfox.intellicommunity.msg.server.service.base.CmdWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author allan
 * @version 1.0.0
 * @date 2020/3/17
 */
@Service
public class CmdWriterBuilder {
    @Autowired
    private CmdControlWriter cmdControlWriter;
    @Autowired
    private CmdSetWriter cmdSetWriter;
    @Autowired
    private DeviceQueryWriter deviceQueryWriter;

    public CmdWriter builder(CmdEnums.Code code) throws MethodNotSupportedException {
        switch (code.getType()) {
            case SET:
                return cmdSetWriter;
            case CONTROL:
                return cmdControlWriter;
            case QUERY:
                return deviceQueryWriter;
            default:
                throw new MethodNotSupportedException("method not supported for cmd type " + code.getType().toString());
        }
    }
}
